{extend name="common/base_page" /}

{block name="title"}库存管理{/block}

{block name="jscssfile"}{/block}

{block name="css"}
<style type="text/css">
body{ background: #ffffff; height:100vh; }
.layui-fluid {
    padding:10px 15px;
}
.layui-tab {
    margin: 0 0;
}
.layui-tab-content{  
  padding:0px;
}
.layui-tab-content .layui-tab-item{
  height:100vh;
}
#bar_box_one{
  padding: 0px 0px 5px 0px;
  margin-bottom:0px;
}
.layui-table, .layui-table-view { margin:0; }
.layui-form-item .layui-input-inline { margin-right: 0px; }
.line-top-tjbox{margin-left:20px;}
</style>
{/block}

{block name="body"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12" style="height:100vh;padding:0;">

            <div class="layui-form-item" id="bar_box_one">
                <a class="layui-btn layui-btn-normal" href="{:url('index/store.kucun/kucun_set')}">库存设置</a>
                <a class="layui-btn layui-btn-normal" href="{:url('index/store.kucun/except_query')}">有效期查询</a>
                <span class="line-top-tjbox">进货总额：0，零售总额：0</span>
                <div class="layui-input-block" style="float: right;">
                  <form class="layui-form" method="post" action="{:url('index/store.kucun/to_excel')}" id="excelForm">
                      <div class="layui-inline" style="margin-right:0px;">
                        <label class="layui-form-label" style="width:30px;padding: 9px 15px 9px 0;">&nbsp;</label>
                        <div class="layui-input-inline" style="width:130px;">
                          <input type="checkbox" id="zero_noshow" name="zero_noshow" value="1" title="零库存不显示" lay-skin="primary">
                        </div>
                      </div>
                      <div class="layui-inline">
                        <label class="layui-form-label" style="width:30px;padding: 9px 15px 9px 0;">类型</label>
                        <div class="layui-input-inline">
                          <select id="drug_type" name="drug_type">
                              <option value="ALL">全部</option>
                              {volist name="ypkc_type_list" id="vo"}
                              <option value="{$vo.id}">{$vo.name}</option>
                              {/volist}
                          </select>
                        </div>
                      </div>
                      <div class="layui-inline">
                        <div class="layui-input-inline">
                          <input type="text" name="keyword" id="keyword" maxlength="10" placeholder="名称/拼音码/五笔码" autocomplete="off" class="layui-input">
                        </div>
                      </div>
                      <div class="layui-inline">
                          <a class="layui-btn layui-btn-normal" onclick="_p = 1;_loadList();">搜索</a>
                          <a class="layui-btn layui-btn-normal" onclick="_Index.downExcel('#excelForm');">导出</a>
                      </div>
                    </form>
                </div>
            </div>
            <div class="layui-tab-content">
                  <div class="layui-tab-item layui-show">
                      <table id="LAY-app-content-comm" lay-filter="LAY-app-content-comm"></table>
                  </div>
            </div>

        </div>
    </div>
</div>
{/block}

{block name="script"}
<script type="text/html" id="table-content-com">
  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="jxc_btn"><i class="layui-icon layui-icon-log"></i>进销存</a>
  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="pc_btn"><i class="layui-icon layui-icon-log"></i>批次</a>
</script>
<script type="text/javascript">
var _p = 1;
$(function(){
  setTimeout(function(){
      _loadList();
  },50);
});
</script>
<script type="text/javascript">
//加载数据
function _loadList()
{
      __showLoadingBox('请稍候...');
      var _zero_noshow = 0;
      if($('#zero_noshow').prop('checked')) _zero_noshow = 1;
      laytable.render({
          elem: '#LAY-app-content-comm'//指定表格元素
          ,url:"{:url('index/store.kucun/index')}"
          ,method:'post'  //提交方式
          ,where:{drugtype:$.trim($('#drug_type').val()),keyword:$.trim($('#keyword').val()),zeronoshow:_zero_noshow,page:_p} //post json数据
          ,page: {layout: ['count', 'prev', 'page', 'next', 'skip'],first: true,last: true}
          ,skin: 'line '  //表格风格 line （行边框风格）row （列边框风格）nob （无边框风格）
        　,even: true    //隔行换色
          ,limit: 20     //每页默认显示的数量
          ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
          ,height: 'full-100' //表格高度，layui 2.2.1 新增 , full-100 为适应最大高度或其它数值500
          ,cols: [[
            {field:'xm_type_txt', width:120, title: '药品类型',sort: true}
            ,{field:'name', minwidth:200, title: '名称'}
            ,{field:'spec', width:120, align:'center', title: '规格',sort: true}
            ,{field:'huogui_no', width:100, align:'center', title: '货柜号',sort: true}
            ,{field:'changjia', width:300, title: '生产厂家'}
            ,{field:'cost_price', width:130, align:'center', title: '进货价',sort: true}
            ,{field:'price', width:130, align:'center', title: '零售价',sort: true}
            ,{field:'ls_unit', width:100, align:'center', title: '单位'}
            ,{field:'stock', width:130, align:'center', title: '库存总量',sort: true}
            ,{fixed: 'right', width: 200, align:'center', title: '操作', toolbar: '#table-content-com'}
          ]]
          ,done:function(datalist,curr,page){
              if(datalist.code == 0)
              {
                $('.line-top-tjbox').empty().html('进货总额：'+datalist.cost_total+'，零售总额：'+datalist.sale_total);
              }else{
                $('.line-top-tjbox').empty();
              }
              __hideLoadingBox();
          }
      });

      laytable.on('tool(LAY-app-content-comm)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
          var _data = obj.data; //获得当前行数据
          var _event = obj.event; //获得 lay-event 对应的值
          if(_event === 'jxc_btn'){ //进销存
            //跳转到新的连接
            __showLoadingBox('请稍候...');
            window.parent.setNewUrl("{:url('index/store.kucun/inout_query')}?drugs_id=" + _data.id + "&drugs_name=" + _data.name);
          }
          if(_event === 'pc_btn'){ //批次
              layer.open({
                type: 2,
                title: '入库批次明细-【'+_data.name+'】',
                shadeClose: true,
                shade: [0.4,'#000000'],
                maxmin: false,
                area: ['1200px', '625px'],
                content: "{:url('index/store.kucun/batch_query')}?drugs_id=" + _data.id + "&drugs_name=" + _data.name 
              });
          }
      });
}
</script>
{/block}